use std::net::SocketAddr;
use dashmap::DashMap;
use super::client::Client;

pub struct ConnMap {
    m: DashMap<SocketAddr, Client>
}

impl ConnMap {

    pub fn new() -> ConnMap {
        ConnMap { m: DashMap::new() }
    }

    pub fn insert(&self, addr: SocketAddr, client: Client) {
        self.m.insert(addr, client);
    }

    pub fn remove(&self, addr: SocketAddr) {
        self.m.remove(&addr);
    }

    pub fn find_by_client_id(&self, client_id: &str) -> Option<Client> {
        for item in self.m.iter() {
            if item.client_id() == client_id {
                return Some(item.value().clone());
            }
        }
        None
    }
}

